<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline size="small">
            <el-form-item label="类型">
              <el-select v-model="listPram.type" clearable class="selWidth"  placeholder="请选择类型" @change="handerSearch">
                <el-option
                  v-for="item in categoryTreeData"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <!--
            <el-form-item label="关键词：">
              <el-input v-model="listPram.fileName" placeholder="请输入关键词" class="selWidth" size="small" clearable>
                <el-button slot="append" icon="el-icon-search" @click="handerSearch" size="small"/>
              </el-input>
            </el-form-item>
          -->
          </el-form>
        </div>
        <router-link :to=" { path:'/agreement/agreementCreat' } ">
          <el-button size="small" type="primary" class="mr10">添加文章</el-button>
        </router-link>
          <el-button size="small" type="primary" class="mr10" @click="handlerGetListData()">刷新</el-button>
      </div>
      <el-table :data="listData.list" size="mini"
                class="table"
                highlight-current-row>
        <el-table-column
          prop="id"
          label="ID"
          min-width="50"
        />
        <el-table-column prop="fileName" label="标题" min-width="180" />
        <el-table-column prop="type" label="类型" min-width="180">
          <template slot-scope="scope">
            <span>{{ scope.row.type =='1'? '隐私政策':'用户服务' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="100" fixed="right" align="center">
          <template slot-scope="scope">
            <router-link :to=" { path:'/agreement/agreementCreat/'+ scope.row.id } ">
              <el-button size="small" type="text" class="mr10">编辑</el-button>
            </router-link>
            <el-button type="text" size="small" @click="handlerDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="constants.page.limit"
        :layout="constants.page.layout"
        :total="listData.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script>
import * as articleApi from '@/api/article.js'
import * as agreementApi from "@/api/agreement.js";
import * as selfUtil from '@/utils/ZBKJIutil.js'
import edit from './edit'
export default {
  name: "AgreementList",
  components: { edit },
  data() {
    return {
      constants: this.$constants,
      listPram: {
        belong: 0,
        //isDel: 0,
        type: null,
        //fileName: '',
        //content: '',
        page: 1,
        limit: this.$constants.page.limit[0]
      },
      categoryTreeData: [
        { id: 1, name: "隐私政策" },
        { id: 2, name: "用户服务" },
      ],
      listData: { list: [], total: 0 },
    }
  },
  mounted() {
    this.handlerGetListData()
  },
  methods: {
    handerSearch() {
      this.listPram.page = 1
      this.handlerGetListData()
    },
    handlerGetListData() {
      agreementApi.TreeListAgreement(this.listPram).then(data => {
        this.listData = data
      })
    },
    handlerDelete(id) {
      this.$confirm('确定删除当前数据', '提示').then(result => {
        agreementApi.DelAgreement(id).then(data => {
          this.$message.success('删除数据成功')
          this.handlerGetListData()
        })
      })
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.handlerGetListData()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.handlerGetListData()
    }
  }
}
</script>

<style scoped lang="scss">
.articleModal{
  z-index: 333 !important;
}
</style>
